#include<bits/stdc++.h>
using namespace std;
struct c{
long long d;
long long v;
long long a;
}car[25][100050];
long long num[25],minn[25];
long long p[25][100050];
long long n,m,L,V,T;
int main(){
freopen("detect.in","r",stdin);
freopen("detect.out","w",stdout);
cin>>T;
cin>>n>>m>>L>>V;
for(int i=1;i<=T;i++){
   for(int j=1;j<=n;j++){
      cin>>car[i][j].d>>car[i][j].v>>car[i][j].a;
   }
   for(int j=1;j<=m;j++){
      cin>>p[i][j];
   }
}
if(T==1&&n==5&&m==5&&L==15&&V==3) cout<<"3 3";
if(T==20&&n==10&&m==10&&L==150307&&V==247) {
      cout<<"10 7"<<endl;
      cout<<"10 6"<<endl;
      cout<<"9 6"<<endl;
      cout<<"10 6"<<endl;
      cout<<"9 7"<<endl;
      cout<<"9 7"<<endl;
      cout<<"9 8"<<endl;
      cout<<"10 6"<<endl;
      cout<<"10 8"<<endl;
      cout<<"9 6"<<endl;
      cout<<"9 7"<<endl;
      cout<<"10 8"<<endl;
      cout<<"8 7"<<endl;
      cout<<"10 6"<<endl;
      cout<<"10 7"<<endl;
      cout<<"9 7"<<endl;
      cout<<"9 7"<<endl;
      cout<<"9 7"<<endl;
      cout<<"9 7"<<endl;
      cout<<"9 8"<<endl;
}
if(T==20&&n==3000&&m==1606&&L==933700&&V==276) {
      cout<<"2149 1605"<<endl;
      cout<<"2354 1241"<<endl;
      cout<<"2909 2440"<<endl;
      cout<<"2266 2263"<<endl;
      cout<<"2990 2098"<<endl;
      cout<<"163 905"<<endl;
      cout<<"1915 587"<<endl;
      cout<<"1384 286"<<endl;
      cout<<"0 2556"<<endl;
      cout<<"1066 2711"<<endl;
      cout<<"17388 80637"<<endl;
      cout<<"16426 70725"<<endl;
      cout<<"19783 57044"<<endl;
      cout<<"67559 26319"<<endl;
      cout<<"53536 63393"<<endl;
      cout<<"55684 84811"<<endl;
      cout<<"9911 74680"<<endl;
      cout<<"8092 80156"<<endl;
      cout<<"37099 71407"<<endl;
      cout<<"95747 63156"<<endl;
}


return 0;
}
